<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加问卷</title>

    <!-- icon小图标 -->
    <link rel="icon" href="../statics/images/icon_S_Bar_Contact.png" type="image/x-icon">
    <!-- Animate.css -->
    <link rel="stylesheet" href="/statics/css/animate.css">
    <!-- Icomoon Icon Fonts-->
    <link rel="stylesheet" href="/statics/css/icomoon.css">
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://www.jq22.com/jquery/bootstrap-3.3.4.css">
    <!-- Magnific Popup -->
    <link rel="stylesheet" href="/statics/css/magnific-popup.css">
    <!-- Flexslider  -->
    <link rel="stylesheet" href="/statics/css/flexslider.css">
    <!-- Theme style  -->
    <link rel="stylesheet" href="/statics/css/style.css">
    <!-- Modernizr JS -->
    <script src="/statics/js/modernizr-2.6.2.min.js"></script>
    <!-- layui -->
    <link rel="stylesheet" href="/statics/layui/css/layui.css">
    <style>
        .layui-layout-admin .layui-logo {
            left: 2rem;
            text-align: left;
            color: #fff;
        }

        #card-show a:hover {
            background-color: yellow;
            bottom: 2rem;
        }
    </style>
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
    onkeydown="on_return();">
    <div class="layui-layout layui-layout-admin">
        <!-- 顶部导航栏 -->
        <nav class="fh5co-nav" role="navigation">
            <div class="container-wrap">
                <div class="top-menu">
                    <div class="row">
                        <div class="col-xs-2">
                            <div id="fh5co-logo"><img src="/statics/images/Gologo.png" alt="" width="180" height="40">
                            </div>
                        </div>
                        <div class="col-xs-10 text-right menu-1">
                            <ul class="lisa_green">
                                <li class="active"><a href="/">首页</a></li>
                                <li><a href="/work">个人主页</a></li>
                                <!-- <li class="has-dropdown">
                                    <a href="#">admin</a>
                                    <ul class="dropdown" style="text-align: center;">
                                        <li><a href="/about_bz">帮助中心</a></li>
                                        <li><a href="/work-single">账户信息</a></li>
                                        <li><a href="#" data-toggle="modal" data-target="#closeAccount" style="color: #5FB878;">退出登录</a></li>
                                    </ul>
                                </li> -->
                            </ul>
                        </div>
                    </div>

                </div>
            </div>
        </nav>

        <!--右侧主体内容区-->
        <!-- <div class="layui-body" style="left: 0rem;margin-top: 1rem;background-color: aqua;width: 50%;"> -->
        <div class="layui-container">

            <!-- <div class="layui-container">  -->
            <div class="layui-row" style="background-color: azure;">
                <div class="layui-col-md1 layui-col-xs1 layui-col-sm1">
                    &nbsp;
                </div>
                <div class="layui-col-md10 layui-col-xs10 layui-col-sm10" style="margin-top: 10rem;">
                    <form class="layui-form" id="addForm" action="/addDone" method="POST">
                        <div class="layui-form-item layui-col-md4 layui-col-xs12 layui-col-sm6">
                            <label class="layui-form-label">问卷：</label>
                            <div class="layui-input-block">
                                <input type="text" name="title" required lay-verify="required" placeholder="请输入主题"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text layui-col-md10 layui-col-xs12 layui-col-sm10">
                            <label class="layui-form-label">说明：</label>
                            <div class="layui-input-block">
                                <textarea name="presentation" placeholder="请输入内容" class="layui-textarea"></textarea>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">类型：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="type" value="0" title="计分问卷型" checked>
                                <!-- <input type="radio" name="type" value="1" title="统计问卷型" disabled> -->
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn layui-col-xs6 layui-col-md1 layui-col-sm2" id="sub" lay-submit
                                    lay-filter="formDemo">创建</button>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>

                </div>
                <div class="layui-col-md1 layui-col-xs1 layui-col-sm1">
                    &nbsp;
                </div>
            </div>
            <!-- </div> -->

        </div>


        <div class="layui-footer" style="left: 0rem;">
            <!-- 底部固定区域 -->
            © Questionnaire survey system
        </div>
    </div>


    <!-- layui -->
    <script src="/statics/static/layui/layui.js"></script>
    <!-- axios -->
    <script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
    <!-- ribbon 背景特效 -->
    <script async type="text/javascript" size="90" alpha="0.2" zIndex="0"
        src="/statics/js/wall_paper/ribbon.js"></script>
    <!-- jQuery -->
    <script src='https://s1.pstatp.com/cdn/expire-1-M/jquery/1.10.2/jquery.min.js'></script>
    <!-- jQuery Easing -->
    <script src="/statics/js/jquery.easing.1.3.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://www.jq22.com/jquery/bootstrap-3.3.4.js"></script>
    <!-- Waypoints -->
    <script src="/statics/js/jquery.waypoints.min.js"></script>
    <!-- Flexslider -->
    <script src="/statics/js/jquery.flexslider-min.js"></script>
    <!-- Magnific Popup -->
    <script src="/statics/js/jquery.magnific-popup.min.js"></script>
    <script src="/statics/js/magnific-popup-options.js"></script>
    <!-- Counters -->
    <script src="/statics/js/jquery.countTo.js"></script>
    <!-- Main -->
    <script src="/statics/js/main.js"></script>
    <script>
        
        layui.use(["form", "layer"], function () {
            var form = layui.form;
            var layer = layui.layer;

            form.on("submit", function (data) {

                let title = data.field.title;
                let presentation = data.field.presentation;
                let type = data.field.type;

                axios({
                    method: "post",
                    url: "/addDone",
                    data: {
                        title: title,
                        presentation: presentation,
                        type: type
                    }
                }).then(function (res) {
                    // axios工具下，服务器真正返回的数据在返回对象的data中
                    res = res.data;
                    let id = Number(res.id)
                    let type = Number(res.type);
                    if (res.code === 200) {
                        if (type === 0) {
                            window.location.href = "/addMessageCount?id=" + id;
                        } else if (type === 1) {
                            window.location.href = "/addMessageStatistics?id=" + id;
                        } else {
                            console.log("请确认你选择的问卷类型是否存在！！！");
                        }

                    } else {
                        console.log("失败");
                        // alert_fn(res.msg)
                        console.log(res.msg);
                    }
                }).catch((err) => {
                    // alert_fn(err),
                    console.log("错啦");
                    console.log(err);
                })

                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            })
        })

        //回车时，默认是登陆
        function on_return() {
            if (window.event.keyCode == 13) {
                if (document.all('sub') != null) {
                    document.all('sub').click();
                }
            }
        }
    </script>
</body>

</html>